package com.sgb.kjwl.view.ui.activity.enterprise;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;

import com.google.android.material.tabs.TabLayout;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityMakeOverBinding;
import com.sgb.kjwl.view.ui.adapter.CommPagerAdapter3;
import com.sgb.kjwl.view.ui.fragment.enterprise.IntellpropFragment;

import java.util.ArrayList;

public class MakeOverActivity extends AppActivity {

    private String[] mTag = {"商标", "版权", "专利"};
    private ArrayList<Fragment> mList;

    @Override
    protected void initView() {
        ActivityMakeOverBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_make_over);

        mList = new ArrayList<>();
        //商标、版权、专利、公司、资产
        String categoryMark = null, categoryCopyright = null, categoryPatent = null, categoryCompany = null, categoryProperty = null;
        int position = getIntent().getIntExtra("position", 0);
        String category = getIntent().getStringExtra("category");
        if (!TextUtils.isEmpty(category)) {
            switch (position) {
                case 0:
                    categoryMark = category;
                    break;
                case 1:
                    categoryCopyright = category;
                    break;
                case 2:
                    categoryPatent = category;
                    break;
                case 3:
                    categoryCompany = category;
                    break;
                case 4:
                    categoryProperty = category;
                    break;
            }
        }
        IntellpropFragment intellpropFragment = IntellpropFragment.newInstance(0, categoryMark);
        IntellpropFragment intellpropFragment2 = IntellpropFragment.newInstance(1, categoryCopyright);
        IntellpropFragment intellpropFragment3 = IntellpropFragment.newInstance(2, categoryPatent);
//        MakeOverFragment companyFragment = MakeOverFragment.newInstance("公司", categoryCompany);
//        MakeOverFragment propertyFragment = MakeOverFragment.newInstance("资产", categoryProperty);
        mList.add(intellpropFragment);
        mList.add(intellpropFragment2);
        mList.add(intellpropFragment3);
//        mList.add(companyFragment);
//        mList.add(propertyFragment);
        binding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                LinearLayout linearLayout = (LinearLayout) LayoutInflater.from(MakeOverActivity.this).inflate(R.layout.item_lin_2, null);
                TextView selectTextView = linearLayout.findViewById(R.id.tab_item_textview);
                selectTextView.setText(tab.getText());
                tab.setCustomView(linearLayout);
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                tab.setCustomView(null);
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
        binding.vpMakeOverMain.setAdapter(new CommPagerAdapter3(getSupportFragmentManager(), mList, mTag) {
            @Override
            public Fragment getItem(int position) {
                return mList.get(position);
            }

            @Override
            public int getCount() {
                return mList.size();
            }

            @Nullable
            @Override
            public CharSequence getPageTitle(int position) {
                return mTag[position];
            }
        });


        binding.tabLayout.setupWithViewPager(binding.vpMakeOverMain);
        binding.tabLayout.getTabAt(0).select();
        binding.vpMakeOverMain.setCurrentItem(position);

    }


}
